package com.UU.J2EE.PizzaStore.dao;

import java.sql.ResultSet;
import java.util.ArrayList;

import com.UU.J2EE.PizzaStore.beans.MenuBean;
import com.UU.J2EE.PizzaStore.beans.PizzaBean;
import com.UU.J2EE.PizzaStore.beans.SizeBean;

public class MenuDao {
	public boolean getMenuForPizza( PizzaBean pizzaBean) {
        ResultSet rs=null;
        boolean hasOrNot = false;
     
        
        try{
            
       
            String sql;
            sql ="SELECT * from menu where pizza= '" + pizzaBean.getId()+"'";
            rs= DBUtil.executeQuery(sql,null);

	    // analyze the result set
	    
	    hasOrNot = rs.next();
	    PizzaDao pizzaDao = new PizzaDao();
	    SizeDao sizeDao = new SizeDao();
	    while(hasOrNot)
	    {
	    	MenuBean menuBean = new MenuBean();
	    	menuBean.setId(rs.getInt("idmenu"));
	    	menuBean.setPrice(rs.getInt("price"));
	    	menuBean.setPizza(pizzaBean);
	    	SizeBean sizeBean = new SizeBean();
	    	sizeBean.setId(rs.getInt("pizzasize"));
	    	sizeDao.getSize(sizeBean);
	    	menuBean.setSize(sizeBean);
	    	pizzaBean.getMenuList().add(menuBean);
	    	hasOrNot = rs.next();
	    }
	}   
	catch(Exception sqle){
            sqle.printStackTrace();
	}
        finally{
        	DBUtil.close(rs, DBUtil.getPs(), DBUtil.getCt());
        }
        return hasOrNot;
  }
}
